<?php

class ForecastDaysModel {

	private $days;		// array(today, tomorrow, etc...)
						// each day is an array of size 24 / y.
	private $has24hours;// true if every hour is spesified.
	
	////////////////////////////////////////////////////////////////////////////
	// 
	//	This modules implements a full forecast for one location, that is, a forecast with five parameters for a seven-day period.
	//	The five parameters are temperature, wind speed, wind direction, pressure and precipitation.
	//	For the first 48 hours, the datapoints are spaces one hour apart, and for the remaining five 24-hour periods, they are spaces three hours apart.
	//	
	//	http://api.yr.no/weatherapi/locationforecast/1.4/documentation#description
	//
	

	public function __construct(){
		$this->days = array();
	}
	
	public function setForecast($day, $hour, $forecast){
		$this->days[$day][$hour] = $forecast;
		if (!$this->has24hours)
			if (count($this->days[$day]) > 8)
				$this->has24hours = true;
	}
	
/*	public function getDayForecasts($nr){
		return $this->days[$nr];
	}
*/	
	public function getHourForecast($day,$hour){
	$hour-=2;
		while ($hour<0){
			$day--;
			$hour = $hour+24;
		}
		
		if($hour<10){
			$hour = '0'.$hour;
		}
	
	
		if(!($this->days[$day][$hour])){
			//echo "tom!!";
			if($hour<6){return $this->days[$day]['00'];}
			else if($hour<12){return $this->days[$day]['06'];}
			else if($hour<18){return $this->days[$day]['12'];}
			else if($hour<24){return $this->days[$day]['18'];}
		}
		
		return $this->days[$day][$hour];
	}
/*	
	public function getXDays($start, $nbOfDays){
		$temp = array();
		for ($i=$start; $i<$nbOfDays; $i++){
			$temp[] = $this->days[$i];
		}
		return $temp;
	}
	
	public function set24hours($boolean){
		$this->has24hours = $boolean;
	}
	
	public function is24hours(){
		return $this->has24hours;
	}
*/
}
?>